#include <my_header.h>
#include <openssl/md5.h>

int calculate(char *file){
    MD5_CTX ctx;
    MD5_Init(&ctx);

    char buf[4096];
    int fd=open(file,O_RDWR);
    if(fd==-1){
        printf("open file error\n");
    }
    while(1){
        bzero(buf,sizeof(buf));
        ssize_t sret = read(fd,buf,sizeof(buf));
        MD5_Update(&ctx,buf,sret);
        if(sret == 0){
            break;
        }
    }
    unsigned char md[16];
    MD5_Final(md,&ctx);
    char str[33] = {0};
    for(int i = 0;i<16;i++){
        char temp[3]={0};
        sprintf(temp,"%02x",md[i]);
        strcat(str,temp);
    }
    printf("str = %s\n",str);
    return 0;
}

